package com.dis.insurance.controller.admin;

import com.dis.common.annotation.CheckPermission;
import com.dis.common.result.PageResult;
import com.dis.common.result.Result;
import com.dis.insurance.service.ReimbursementService;
import com.dis.pojo.queryDTO.ReimbursementPageQueryDTO;
import com.dis.pojo.vo.ReimbursementVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/reimbursement")
@Api(tags = "报销记录管理")
@Slf4j
public class ReimbursementController {

    @Autowired
    private ReimbursementService reimbursementService;

    @GetMapping("/page/data")
    @ApiOperation("分页查询报销记录——用于统计")
    @CheckPermission("reimbursement:query:data")
    public Result<PageResult> pageData(ReimbursementPageQueryDTO reimbursementPageQueryDTO) {
        PageResult pageResult = reimbursementService.pageQuery(reimbursementPageQueryDTO);
        return Result.success(pageResult);
    }
    @GetMapping("/page")
    @ApiOperation("分页查询报销记录")
    @CheckPermission("reimbursement:query")
    public Result<PageResult> page(ReimbursementPageQueryDTO reimbursementPageQueryDTO) {
        PageResult pageResult = reimbursementService.pageQuery(reimbursementPageQueryDTO);
        return Result.success(pageResult);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据ID查询报销记录")
    @CheckPermission("reimbursement:query")
    public Result<ReimbursementVO> getById(@PathVariable Long id) {
        ReimbursementVO reimbursementVO = reimbursementService.getById(id);
        return Result.success(reimbursementVO);
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除报销记录")
    @CheckPermission("reimbursement:delete")
    public Result deleteById(@PathVariable Long id) {
        reimbursementService.deleteById(id);
        return Result.success();
    }

    @PostMapping("/audit/{id}")
    @ApiOperation("审核报销记录")
    @CheckPermission("reimbursement:audit")
    public Result audit(@PathVariable Long id, @RequestParam Integer status,
                        @RequestParam(required = false) String auditComment) {
        reimbursementService.audit(id, status, auditComment);
        return Result.success();
    }
}